<div class="area-wrapper"></div>
<div class="search-wrapper">
    <h5>活动时间</h5>
    <div class="search-box">
        <input type="text" name="startDate" class="start-date" placeholder="年-月-日" readonly /> - <input type="text" name="endDate" class="end-date" placeholder="年-月-日" readonly /><a href="" class="abtn-search">查询</a>
    </div>
    <div class="search-data">
        <table>
            <thead>
            <tr>
                <td>基地性质</td>
                <td>基地数</td>
                <td>成员数</td>
                <td>志愿时间</td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>已挂靠</td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td>未挂靠</td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td>合计</td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<script>
    $(function(){
        $('.area-wrapper').load('/admin/template/home/welcome/area.html')
        $('.start-date,.end-date').datetimepicker({
            minView: "month",
            format: 'yyyy-mm-dd',
            language: 'zh',
            autoclose: 1,
            maxDate: new Date()
        })
        $('.abtn-search').on('click', function(){
            var startDate = $('.start-date').val(), endDate = $('.end-date').val(), selectedCode = sessionStorage.getItem("selectedCode") || null
            if(startDate >= endDate){
                alert("起始日期必须小于结束日期")
                return
            }
            $.ajax({
                url : "/admin/statistics/timeCount",
                data: JSON.stringify({
                    startDate: startDate,
                    endDate: endDate,
                    jurisdiction: selectedCode
                }),
                headers: {
                    'content-type': 'application/json'
                },
                dataType:'json',
                type:'post',
                success:function(data){
                    $('.search-data tbody').empty()
                    $.each(data.data, function(index,val){
                        switch (val.linkStatus){
                            case 1:
                                $("<tr><td>已挂靠</td>"+"<td>"+val.groupNumber+"</td>"+"<td>"+val.signNumber+"</td>"+"<td>"+val.timeNumber+"</td>"+"</td>"+"</tr>").appendTo($('.search-data tbody'))
                                break
                            case 2:
                                $("<tr><td>未挂靠</td>"+"<td>"+val.groupNumber+"</td>"+"<td>"+val.signNumber+"</td>"+"<td>"+val.timeNumber+"</td>"+"</td>"+"</tr>").appendTo($('.search-data tbody'))
                                break
                            case 999:
                                $("<tr><td>合计</td>"+"<td>"+val.groupNumber+"</td>"+"<td>"+val.signNumber+"</td>"+"<td>"+val.timeNumber+"</td>"+"</td>"+"</tr>").appendTo($('.search-data tbody'))
                        }
                    })
                }
            })
            return false
        })
    })
</script>